/*
 * @lc app=leetcode.cn id=206 lang=cpp
 *
 * [206] 反转链表
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution
{
public:
    struct ListNode *reverseList(struct ListNode *head)
    {
        ListNode *new_head, *temp;

        //初始化 逆转新表头为空
        new_head = NULL; 

        while (head)
        { //当旧表头不为空时
            temp = head->next;  //先找到原链表的下一个结点
            head->next = new_head; 

            new_head = head;    //前进
            head = temp;
        }

        return new_head;
    }
};

// @lc code=end
